{{template "base" .}}

{{define "content"}}
<div class="blog-container">
    <div class="main-content">
        <div class="post-list">
            {{range $id, $post := .PostList.Lists}}
            <article class="post-item">
                <h2 class="post-title">
                    <a href="/read/{{$post.ID}}">{{$post.Title}}</a>
                </h2>
                <div class="post-meta">
                    <span class="post-date">{{$post.CreateTime.Format "2006-01-02"}}</span>
                    <span class="post-category">{{$post.TypeName}}</span>
                    <span class="post-views">{{$post.ReadCount}} 阅读</span>
                </div>
                <div class="post-excerpt">
                    {{$post.Content}}
                </div>
                <div class="post-tags">
                    {{range $post.Tags}}
                    <span class="tag">{{.}}</span>
                    {{end}}
                </div>
            </article>
            {{end}}
        </div>

        <!-- 分页 -->
        {{if gt .PostList.PageNum 1}}
        <div class="pagination">
            {{if gt .currentPage 1}}
            <a href="/?page={{subtract .currentPage 1}}" class="prev">上一页</a>
            {{end}}
            
            {{range $i := sequence .PostList.PageNum}}
            <a href="/?page={{$i}}" class="{{if eq $i $.currentPage}}current{{end}}">{{$i}}</a>
            {{end}}
            
            {{if lt .currentPage .PostList.PageNum}}
            <a href="/?page={{add .currentPage 1}}" class="next">下一页</a>
            {{end}}
        </div>
        {{end}}
    </div>

    <aside class="sidebar">
        <div class="widget">
            <h3>最新文章</h3>
            <ul class="recent-posts">
                {{range .newPosts}}
                <li><a href="/read/{{.ID}}">{{.Title}}</a></li>
                {{end}}
            </ul>
        </div>
    </aside>
</div>
{{end}}